#!/usr/bin/python
# -*- coding: utf-8 -*-

import time
import MySQLdb

conn = MySQLdb.Connection("172.16.7.58", "root", "researchsucks", "X", 3306)
conn.set_character_set("utf8");
cur = conn.cursor()

cur.execute("select distinct video_id from user_browsed")
video_ids = cur.fetchall()

ISOTIMEFORMAT='%Y-%m-%d'
start_time = time.time() - 30 * 24 * 3600;
start_time_str = time.strftime(ISOTIMEFORMAT, time.localtime(start_time))

for data in video_ids:
    cur.execute("select pubdate from video_info where id='" + data[0] + "'")
    for data2 in cur.fetchall():
        t = time.mktime(data2[0].timetuple())
        if t < start_time:
            cur.execute("delete from user_browsed where video_id='" + data[0] + "'")
        break

cur.close()
conn.close()
